package com.mzy.linear_struct;

public class HighlightSubstring {
    public static void main(String[] args) {
        String mainString = "你好，世界";
        String substring = "，世";

        String highlightedString = highlightSubstring(mainString, substring);
        System.out.println(highlightedString);
    }

    public static String highlightSubstring(String mainString, String substring) {
        // ANSI转义码：红色文本颜色
        String redColor = "\u001B[31m";
        // ANSI转义码：重置文本颜色
        String resetColor = "\u001B[0m";

        // 将子字符串替换为带有红色标记的子字符串
        String highlightedString = mainString.replace(substring, redColor + substring + resetColor);
        return highlightedString;
    }
}
